﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace TurnamentOrganizer
{
    public partial class PaymentForm : Form
    {
        private Tournament main;

        public PaymentForm(Tournament main)
        {
            InitializeComponent();
            this.main = main;

            foreach (Player item in main.playerList)
            {
                if (item.HasPaid)
                {
                    listBoxPaid.Items.Add(item.Name);
                }
                else
                {
                    listBoxNotPaid.Items.Add(item.Name);
                }
            }
            
        }        

        private void buttonSave_Click(object sender, EventArgs e)
        {
            if (listBoxNotPaid.SelectedItem != null)
            {
                DialogResult betalt = MessageBox.Show("Har " + listBoxNotPaid.SelectedItem.ToString() + " Betalt?", "Betaling", MessageBoxButtons.YesNo);
                if (betalt.Equals(DialogResult.Yes))
                {
                    listBoxPaid.Items.Add(listBoxNotPaid.SelectedItem);
                    Player selectedPlayer = main.playerList.Single(Player => Player.Name == listBoxNotPaid.SelectedItem.ToString());
                    listBoxNotPaid.Items.Remove(listBoxNotPaid.SelectedItem);
                    selectedPlayer.HasPaid = true;
                } 
            }
        }

        private void buttonNotPaid_Click(object sender, EventArgs e)
        {
            if (listBoxPaid.SelectedItem != null)
            {
                DialogResult betalt = MessageBox.Show("Skal betalingen for " + listBoxPaid.SelectedItem.ToString() + " fjernes?", "Betaling", MessageBoxButtons.YesNo);
                if (betalt.Equals(DialogResult.Yes))
                {
                    listBoxNotPaid.Items.Add(listBoxPaid.SelectedItem);
                    Player selectedPlayer = main.playerList.Single(Player => Player.Name == listBoxPaid.SelectedItem.ToString());
                    listBoxPaid.Items.Remove(listBoxPaid.SelectedItem);
                    selectedPlayer.HasPaid = false;
                }
            }
        }
    }
}
